<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../../css/api.css" />
	<link rel="stylesheet" type="text/css" href="./css/my.css" />
</head>

<body>
	<div class="aui_order_set set_style set_js">
		<ul class="aui-list-view aui-in">
			<li class="aui-list-view-cell">
				<span>头像</span>
				<div class="userimg" onclick="loadAvatar(this)"><img id="avatar" src="./image/default_avatar.png">
				</div>
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
			<li class="aui-list-view-cell">
				<span>手机号</span>
				<label id="mobile"></label>
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
			<li class="aui-list-view-cell" onclick="">
				<span>用户名</span>
				<label id="username"></label>
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
		</ul>
	</div>

	<div class="aui_order_set set_style set_mj">
		<ul class="aui-list-view aui-in">
			<li class="aui-list-view-cell">
				<span>分享商品带APP下载</span>
				<input type="checkbox" class="aui-switch aui-pull-right" id="isdownloadapp" checked onchange="statechange(this,'downloadapp')">
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
			<li class="aui-list-view-cell">
				<span>订单消息通知</span>
				<input type="checkbox" class="aui-switch aui-pull-right" id="isordernotice" checked onchange="statechange(this,'ordernotice')">
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
			<li class="aui-list-view-cell">
				<span>清理缓存</span>
				<hc id="cachesize">1.0MB</hc>
				<ql id="clearcache">清理</ql>
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
			<li class="aui-list-view-cell">
				<span>版本号</span>
				<label id="version">v.1.0.0</label>
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
			<li class="aui-list-view-cell">
				<span>源码版本号</span>
				<label id="systemv">v.1.0.0</label>
				<div class="aui_set_jt">
					<img src="./image/my_right_jt.png">
				</div>
			</li>
		</ul>
	</div>
	<div class="weui_btn weui_btn_default text set_login" onclick="logout()">退出登录</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/config.js"></script>
<script type="text/javascript" src="../../script/zepto.min.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
	apiready = function() {
		getmemberinfo();
		$("#version").text("v" + api.appVersion);
		$("#systemv").text("v" + SYSTEM_V);
		api.getCacheSize(function(ret) {
			var size = ret.size;
			var mbsize = (size / (1024 * 1024)).toFixed(2);
			$("#cachesize").text(mbsize + "MB");
		});
		$("#clearcache").click(function() {
			api.showProgress({
				title: '清理中',
				text: '请稍后...',
				modal: false
			});
			api.clearCache(function() {
				api.hideProgress();
				api.toast({
					msg: '清除完成'
				});
				api.getCacheSize(function(ret) {
					var size = ret.size;
					var mbsize = (size / (1024 * 1024)).toFixed(2);
					$("#cachesize").text(mbsize + "MB");
				});
			});
		});
	}

	function getmemberinfo() {
		var user = isLogin();
		if (user) {
			$("#username").text(user.realname||user.nick||user.taobao_user_nick||user.wxnick||user.qqnick|| "未设置");
			$("#mobile").text(user.mobile);
			if (user.isdownloadapp == 1) {
				$("#isdownloadapp").attr("checked", true);
			} else {
				$("#isdownloadapp").removeAttr("checked");
			}
			if (user.isordernotice == 1) {
				$("#isordernotice").attr("checked", true);
			} else {
				$("#isordernotice").removeAttr("checked");
			}

			if (user.avatar) {
				$("#avatar").attr("src", user.avatar);
			}
		} else {
			//goTologin();
			$("#username").text("登录");
		}
	}

	function statechange(obj, type) {
		var data = new Object();
		if (type == "ordernotice") {
			data.isordernotice = $(obj).is(':checked') ? 1 : 0;
		}
		if (type == "downloadapp") {
			data.isdownloadapp = $(obj).is(':checked') ? 1 : 0;
		}
		postDataLogin('updateUserInfo', data, function(ret, err) {
			showToast(ret.data || ret.msg);
			var jsfun = 'location.reload();';
			api.execScript({
				name: 'root',
				frameName: 'my_win',
				script: jsfun
			});
		})
	}

	function loadAvatar(obj) {
		api.actionSheet({
			title: '选择图片来源',
			cancelTitle: '取消',
			buttons: ['照相机', '相册']
		}, function(ret, err) {
			if (3 == ret.buttonIndex) {
				return;
			}
			var sourceType = 'album';
			if (1 == ret.buttonIndex) {
				sourceType = 'camera';
			}
			api.getPicture({
				sourceType: sourceType,
				encodingType: 'jpg',
				mediaValue: 'pic',
				destinationType: 'base64',
				allowEdit: true,
				quality: 100,
				targetWidth: 500,
				targetHeight: 300,
				saveToPhotoAlbum: false
			}, function(ret, err) {
				var data = new Object();
				data.files = [];
				data.files.push(ret.data);

				upLoadPic(data, function(ret, err) {
					if (ret.code == 1) {
						$("#avatar").attr("src", ret.url);
						data = {};
						data.avatar = ret.url;
						postDataLogin('updateUserInfo', data, function(rets) {
							showToast('上传成功!');
							var jsfun = 'location.reload();';
							$api.setStorage('my_click', 1);
							api.execScript({
								name: 'root',
								frameName: 'my_win',
								script: jsfun
							});
						});
					} else {
						showToast('上传失败!');
					}
				});
			});
		});
	}
	//上传图片
	function upLoadPic(data, cb) {
		if (!data.files) {
			return;
		}
		// 提交JSON数据
		postDataLogin('uploadpic', {}, function(ret, err) {
			typeof cb == 'function' && cb(ret, err);
		}, {
			upfile: data.files
		})
	}


	function logout() {
		postData(URL + 'Login/Logout', {}, function(ret, err) {
			if (ret.code == 1) {
				$api.rmStorage('taobao_user');
				showToast('你已退出登录!');
				var jsfun = 'location.reload();';
				api.execScript({
					name: 'root',
					frameName: 'my_win',
					script: jsfun
				});
				api.closeWin({
					name: 'user_set_win'
				});
			}
		});
	}
</script>

</html>
